package com.xbongbong.paas.enums;


import com.xbongbong.i18n.util.I18nMessageUtil;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * @ClassName MobileModeTypeEnum
 * @Description 移动端首页模式
 * @Author mengna.Deng
 * @Date 2021/11/29 19:07
 * @Version 1.0
 */
public enum MobileIndexModeEnum {
    /**
     * 经典模式
     */
    CLASSIC_MODE(0,"classicMode", "enum.mobileIndexMode.name.classic_mode"),
    /**
     * 专注模式
     */
    FOCUS_MODE(1,"focusMode", "enum.mobileIndexMode.name.focus_mode"),
            ;

    public int code;
    public String alias;
    public String name;

    MobileIndexModeEnum() {
    }

    MobileIndexModeEnum(Integer code, String alias, String name){
        this.code = code;
        this.alias = alias;
        this.name = name;
    }

    public int getCode() {
        return code;
    }

    public String getAlias() {
        return alias;
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }


    public static List<MobileIndexModeEnum> getAllEnum(){
        List<MobileIndexModeEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static MobileIndexModeEnum getByCode(Integer code) {
        for(MobileIndexModeEnum mobileModeTypeEnum: values()) {
            if(Objects.equals(mobileModeTypeEnum.getCode(),code)) {
                return mobileModeTypeEnum;
            }
        }
        return null;
    }


    public static MobileIndexModeEnum getByAlias(String alias) {
        if(alias != null){
            for (MobileIndexModeEnum cacheCode : values()) {
                if (Objects.equals(cacheCode.getAlias(), alias)) {
                    return cacheCode;
                }
            }
        }
        return null;
    }

    public static List<String> getAliasList() {
        List<String> alias = new ArrayList<>();
        for (MobileIndexModeEnum cacheCode : values()) {
            alias.add(cacheCode.getAlias());
        }
        return alias;
    }
}
